package com.nsgf.library.ui.product;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.RecyclerView;

import com.kunminx.architecture.ui.page.DataBindingConfig;
import com.kunminx.architecture.ui.state.State;
import com.kunminx.binding_recyclerview.adapter.SimpleDataBindingAdapter;
import com.nsgf.library.data.bean.ProductBean;
import com.nsgf.library.data.response.ResponseStatus;
import com.nsgf.library.domain.request.AccountRequester;
import com.nsgf.library.ui.adapter.DiffUtils;
import com.nsgf.library.ui.page.BaseActivity;
import com.nsgf.library.ui.page.StateHolder;
import com.nsgf.library.utils.StringUtil;
import com.nsgf.library.utils.ToastUtils;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;
import com.zhht.htzx.BR;
import com.zhht.htzx.R;
import com.zhht.htzx.databinding.ActivityExpectationListBinding;
import com.zhht.htzx.databinding.ActivityProductListBinding;
import com.zhht.htzx.databinding.ItemProductBinding;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 商品列表
 */
public class ExpectationListActivity extends BaseActivity {

    private ProductListStates mStates;

    private SimpleDataBindingAdapter<ProductBean, ItemProductBinding> mAdapter;

    private AccountRequester mAccountRequester;


    @Override
    protected void initViewModel() {
        mStates = new ProductListStates();
        mAccountRequester = new AccountRequester();
    }

    @Override
    protected DataBindingConfig getDataBindingConfig() {
        mAdapter = new SimpleDataBindingAdapter<ProductBean, ItemProductBinding>(this, R.layout.item_product, DiffUtils.getInstance().getProductItemCallback()) {
            @Override
            protected void onBindItem(ItemProductBinding binding, ProductBean item, RecyclerView.ViewHolder holder) {
                binding.setVm(item);
                if (StringUtil.isEmpty(item.getTenantName())) {
                    binding.tvItemProductTenantName.setVisibility(GONE);
                } else
                    binding.tvItemProductTenantName.setVisibility(VISIBLE);
            }
        };
        return new DataBindingConfig(R.layout.activity_expectation_list, BR.vm, mStates)
                .addBindingParam(BR.adapter, mAdapter);
    }

    private ActivityExpectationListBinding mBinding;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getLifecycle().addObserver(mAccountRequester);
        mBinding = (ActivityExpectationListBinding) getBinding();
        mStates.titleBar.set(getIntent().getStringExtra("title"));

    }


    private int page = 0;
    private final Handler handler = new Handler(Looper.getMainLooper());


    public static class ProductListStates extends StateHolder {

        public final State<List<ProductBean>> list = new State<>(new ArrayList<>());
        public final State<String> searchName = new State<>("");
    }
}
